package com.servlet.news;

import com.dao.NewsDao;
import com.dao.NewsInfo;
import com.entity.News;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author admin
 */
@WebServlet(name = "NewsSelectOneServlet",urlPatterns = "/NewsSelectOneServlet.filter")
public class NewsSelectOneServlet extends HttpServlet {


    private NewsDao newsdao = new NewsInfo();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String n_id = request.getParameter("n_id");
        try {
            News news = newsdao.selectNews(Integer.getInteger(n_id));
            System.out.println("doGet"+news.toString());
            request.setAttribute("news",news);
            request.getRequestDispatcher("/WEB-INF/page/news.jsp").forward(request,response);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
